// 获取菜单，渲染页面
let search = (function () {
    let newData = []

    function render(data = []) {
        newData = [...newData, ...data]

        let page = ''

        newData.forEach(item => {
            // console.log(item.img);
            item.img = item.img.replace('images', '../assets/imgaes');
            page += `
            <div class="nv-con-col">
                    <a href="../pages/${item.titlehref}">
                        ${item.img}
                    </a>
                    <p>
                        ${item.name}
                    </p>
                </div>
            `
        })
        $('.row').html(page)
        // 点击更多 多显示一行
        // console.log($('#info>.nv-con-col'));
        $('.nv-con-col').eq(7).click(function (e) {

            e.preventDefault();
      
          })
        $('.nv-con-col').eq(7).click(function () {
            console.log('1');
            $('.nv-con-col').eq(7).nextAll().slideToggle();
        })

    }
    $.ajax({
        url: 'http://chst.vip:1234/api/getindexmenu',
        catch:true    
        })
        .then(res => {
            console.log(res);
            render(res.result)
        })
})()

// 商品请求，渲染页面
let product = (function () {
    let newData = [] //接受请求到的数据
    function render(data = []) {
        newData = [...data, ...newData]
        console.log(newData);
        let page = ''
        newData.forEach(item => {
            page += `
            <li proid="${item.productId}">
            <a class="clearfix">
                <div class="img fl">
                    ${item.productImg2}
                </div>
                <div class="infoR">
                    <div class="title">
                        <h4>${item.productName}
                            <span>${item.productPinkage}</span>
                        </h4>
                    </div>
                    <div class="other">
                        <span class="mall fl">${item.productFrom}|${item.productTime}</span>
    
                        <em class="fr">
                            <i class="iconfont icon-xiaoxi "></i>
                            <span> ${item.productComCount}</span>
                        </em>
    
                    </div>
    
                </div>
            </a>
        </li>
            `
        })
        $('.info').html(page)
        // 点击事件
        $('.info').on('click','li',function(){
            let proid = $(this).attr('proid');
            console.log(proid);
            location.href = `../pages/moneyproduct.html?productid=${proid}`
        })
    }
    $.ajax({
        url: 'http://chst.vip:1234/api/getmoneyctrl',
        
        catch:true    
        })
        .then(res => {
            console.log(res);
            render(res.result) // 把获取到的数据当作参数传入
        })
        $('ul').on('click','li',function(){
            // console.log(this);
            let productid = $(this).attr("productid")
            console.log($('productid'));
            location.href = `./detail.html?productid=${productid}`
        })

})()

